package com.collect.senegal.zhiScene.zhiCollection.zhiAdmin;

import android.annotation.SuppressLint;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.collect.senegal.R;
import com.collect.senegal.zhiBase.BaseActivity;
import com.collect.senegal.zhiGlobal.zhiAppSettings.ZHIProjectRouter;
import com.collect.senegal.zhiHelper.ZHIMainProcessHelper;

@SuppressLint("NonConstantResourceId")
@Route(path = ZHIProjectRouter.ZHI_ADMIN)
public class ZHIAdminActivity extends BaseActivity implements ZHIAdminFragmentInterface {

    private FragmentManager mFragmentManager;
    private ZHIAdminGroupMoneyFragment mZHIAdminGroupMoneyFragment;
    private ZHIAdminGroupOrderFragment mZHIAdminGroupOrderFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_admin_v3;
    }

    @Override
    protected void initInjector() {
    }

    @Override
    protected void initView() {
        try {
            mFragmentManager = getSupportFragmentManager();
            selecFragment(ZHIMainProcessHelper.getInstance().getLoginEntity().isLevelBPlus()?0:1);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onFinish() {
        finish();
    }

    private void selecFragment(int indext) {
        FragmentTransaction fragemntTransaction = mFragmentManager.beginTransaction();
        hideFragment(fragemntTransaction);
        switch (indext) {
            case 0: {
                if (null == mZHIAdminGroupMoneyFragment) {
                    mZHIAdminGroupMoneyFragment = new ZHIAdminGroupMoneyFragment();
                    fragemntTransaction.add(R.id.content, mZHIAdminGroupMoneyFragment);
                } else {
                    fragemntTransaction.show(mZHIAdminGroupMoneyFragment);
                }
                break;
            }
            case 1: {
                if (null == mZHIAdminGroupOrderFragment) {
                    mZHIAdminGroupOrderFragment = new ZHIAdminGroupOrderFragment();
                    fragemntTransaction.add(R.id.content, mZHIAdminGroupOrderFragment);
                } else {
                    fragemntTransaction.show(mZHIAdminGroupOrderFragment);
                }
                break;
            }
            default:
                break;
        }
        fragemntTransaction.commit();
    }

    private void hideFragment(FragmentTransaction fragemntTransaction) {
        if (fragemntTransaction == null) return;
        if (null != mZHIAdminGroupMoneyFragment)
            fragemntTransaction.hide(mZHIAdminGroupMoneyFragment);
        if (null != mZHIAdminGroupOrderFragment)
            fragemntTransaction.hide(mZHIAdminGroupOrderFragment);
    }
}
